// 碳足迹
(function () {
    var chartDom = document.getElementById('tanzuji');
    var myChart = echarts.init(chartDom);
    var option;
    option = {
        dataset: {
            source: [
                ['score', 'amount', 'product'],
                [89.3, 58212, '水'],
                [57.1, 78254, '电'],
                [74.4, 41032, '气'],
                [50.1, 12755, '纸张'],
                [89.7, 20145, '钢铁'],
                [68.1, 79146, '塑料'],
                [19.6, 91852, '木头'],
                [10.6, 101852, '油漆'],
                [32.7, 20112, '泡沫']
            ]
        },
        grid: { containLabel: true },
        xAxis: { name: '排放', axisLabel: { textStyle: { color: '#fff' } } },
        yAxis: { type: 'category', axisLabel: { textStyle: { color: '#fff' } } },
        visualMap: {
            orient: 'horizontal',
            left: 'center',
            min: 10,
            max: 100,
            text: ['高排放量', '低排放量'],
            // Map the score column to color
            dimension: 0,
            inRange: {
                color: ['#33D9E2', '#FEA352', '#FF3962']
            },
            textStyle: {
                color: '#fff'
            }
        },
        series: [
            {
                type: 'bar',
                encode: {
                    x: 'amount',
                    y: 'product'
                },
                itemStyle: {
                    normal: {
                        color: function (params) {
                            var colors = ['#33D9E2','#FEA352','#71C9B6','#EFE058','#FEA352','#FF3962','#F2A65B','#69CBBC','#FF4F5F'];
                            return colors[params.dataIndex];
                        }
                    }
                }
            }
        ]
    };

    option && myChart.setOption(option);
})();

// 碳排放和碳补偿
(function () {
    var tanzhonghe = document.getElementById('tanzb');
    var tanzhongheChart = echarts.init(tanzhonghe);
    var option;

    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // Use axis to trigger tooltip
                type: 'shadow'        // 'shadow' as default; can also be 'line' or 'shadow'
            },
            textStyle: {
                color: '#fff'
            }
        },
        legend: {
            data: ['碳排放', '碳补偿'],
            textStyle: {
                color: '#fff'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'],
            axisLabel: {
                textStyle: {
                    color: '#fff'
                }
            }
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                textStyle: {
                    color: '#fff'
                }
            }
        },
        series: [
            {
                name: '碳排放',
                type: 'bar',
                stack: 'total',
                label: {
                    show: true
                },
                emphasis: {
                    focus: 'series'
                },
                data: [320, 302, 301, 334, 390, 330, 320, 320, 302, 301, 334, 390, 330, 320, 320, 302, 301, 334, 390, 330, 320, 20, 302, 301, 334, 390, 320, 20, 302, 323],
                itemStyle: {
                    color: '#4075FF'
                }
            },
            {
                name: '碳补偿',
                type: 'bar',
                stack: 'total',
                label: {
                    show: true
                },
                emphasis: {
                    focus: 'series'
                },
                data: [120, 132, 101, 134, 90, 230, 210, 20, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210, 201, 134, 90, 230, 210, 120, 132, 154, 201],
                itemStyle: {
                    color: '#1BCBFF'
                }
            }
        ]
    };

    option && tanzhongheChart.setOption(option);
})();

// 碳减少
(function () {
    var tanjianshaoDiv = document.getElementById('qileixing');
    var tanjianshaoChart = echarts.init(tanjianshaoDiv);
    var option;

    option = {
        legend: {
            right: 15,
            top:'16%',
            orient: 'vertical',
            textStyle: {
                color: '#fff'
            }
        },
        series: [
            {
                name: '面积模式',
                type: 'pie',
                radius: [40, 180],
                center: ['50%', '50%'],
                roseType: 'area',
                itemStyle: {
                    borderRadius: 8,
                    normal: {
                        color: function (params) {
                            var colors = ['#FF3962','#FEA352','#EFE058','#33D9E2','#4075FF','#886CF7','#F2A65B','#69CBBC','#FF4F5F'];
                            return colors[params.dataIndex];
                        }
                    }
                },
                data: [
                    { value: 40, name: '办公室' },
                    { value: 38, name: '打印室' },
                    { value: 32, name: '锅炉房' },
                    { value: 30, name: '厂房一' },
                    { value: 28, name: '厂房二' },
                    { value: 26, name: '厂房三' },
                    { value: 22, name: '厂房四' },
                    { value: 18, name: '厂房五' }
                ]
            }
        ]
    };

    option && tanjianshaoChart.setOption(option);
})();
